package com.wpw.java8demo;

import java.util.Arrays;
import java.util.OptionalInt;

import org.junit.Test;

public class ReduceTest {

	@Test
	public void test1() {
		int[] arrays = {1,2,3,4,5,6,7,8,9};
		int reduce = Arrays.stream(arrays)
			.reduce(0, (a ,b) -> a + b);
		System.out.println(reduce);
		
		int reduce2 = Arrays.stream(arrays)
				.reduce(0, Integer::sum);
		System.out.println(reduce2);
		
		OptionalInt reduce3 = Arrays.stream(arrays)
			.reduce(Integer::sum);
		System.out.println(reduce3.getAsInt());
		
		int reduce4 = Arrays.stream(arrays)
			.reduce(0, Integer::max);
		System.out.println("max:" + reduce4);
		
		OptionalInt reduce5 = Arrays.stream(arrays)
			.reduce((a,b) -> a >b ? a : b);
		System.out.println("max:" + reduce5.getAsInt());
		
	}
	
}
